//package com.turing.post.util;

import java.io.*;
import java.util.Vector;

import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FileSet;

public class genApplicationXmlTask extends Task
{
    private String packageName;
    private String jarName;
    private String xmlFile;
    
    public void setPackageName( String packageName )
    {
        this.packageName = packageName;
    }

    public void setJarName( String jarName )
    {
        this.jarName = jarName;
    }
    
    public void setXmlFile( String xmlFile )
    {
        this.xmlFile = xmlFile;
    }

    public void execute() throws BuildException
    {
        File write = null;
        BufferedWriter bw = null;
                
        try {
            write = new File( xmlFile );
   
            bw = new BufferedWriter( new FileWriter(write) );
   
            bw.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
            bw.newLine();
            
            bw.write( "<application xmlns=\"http://java.sun.com/xml/ns/j2ee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.4\">" );
            bw.newLine();
        
            bw.write( "\t<description>" );
            bw.write( packageName );
            bw.write( " Shared Library</description>" );
            bw.newLine();
        
            bw.write( "\t<display-name>" );
            bw.write( packageName );
            bw.write( " Shared Library</display-name>" );
            bw.newLine();

            bw.write( "\t<module>" );
            bw.newLine();
            
            bw.write( "\t\t<ejb>" );
            bw.write( jarName );
            bw.write( "</ejb>" );
            bw.newLine();
        
            bw.write( "\t</module>" );
            bw.newLine();

            bw.write( "</application>" );
            bw.newLine();

            bw.close();
        }
        catch ( Exception ex_ ){
            throw new BuildException( ex_.toString() );
        }
        finally {
            write = null;
            bw = null;
        }
    }
}

/*
 * end of genApplicationXml.java
 */
